import { IFeidaoAiWeappPage } from '../../../../interfaces';
import get_record_manager from './_get-record-manager';

/**
 * @see [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-camera.html)
 */
export default function start_record(fd: IFeidaoAiWeappPage, duration?: number, sampleRate?: 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000, numberOfChannels?: number, encodeBitRate?: number, format?: 'aac' | 'mp3', frameSize?: number) {
	const options = {};

	if (duration !== undefined) {
		Object.assign(options, {
			duration
		});
	}
	if (sampleRate !== undefined) {
		Object.assign(options, {
			sampleRate
		});
	}
	if (numberOfChannels !== undefined) {
		Object.assign(options, {
			numberOfChannels
		});
	}
	if (encodeBitRate !== undefined) {
		Object.assign(options, {
			encodeBitRate
		});
	}
	if (format !== undefined) {
		Object.assign(options, {
			format
		});
	}
	if (frameSize !== undefined) {
		Object.assign(options, {
			frameSize
		});
	}
	const ctx = get_record_manager(fd);
	ctx.start(Object.assign(options));
}
